package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Reference
    private SetmealService setmealService;

    @RequestMapping("/getSetmeal")                                                      //浏览器端发送请求
    public Result getSetmeal(){
        try {
            List<Setmeal> list = setmealService.getSetmeal();                           //调用service层方法,获得setmeal数据,并封装成集合
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,list);//返回成功数据
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);       //返回错误数据
        }
    }

    @RequestMapping("/findById")                                                        //浏览器端发送请求
    public Result findById(Integer id){                                                 //浏览器端发送的id,根据id进行查询操作
        try {
            Setmeal setmeal = setmealService.findById(id);                              //调用service层方法
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal); //响应结果

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);

        }
    }
}
